//
//  playSerengetiMobile1AppDelegate.m
//  playSerengetiMobile1
//
//  Created by Lita Gratrix on 10/22/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "playSerengetiMobile1AppDelegate.h"
#import "LogonView.h"
#import "MainView.h"
#import "UserHome.h"
#import "UserProfile.h"
#import "CheckInView.h"

@implementation playSerengetiMobile1AppDelegate

@synthesize window;
@synthesize logonView;
@synthesize mainView, userHomeView, userProfileView, checkInPage;
@synthesize loggedInAs, JSessionCookieValue;
@synthesize baseURL;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    
	
	//baseURL = @"http://www.playserengeti.com/serengeti/";
	baseURL = @"http://localhost:8080/serengeti/";
	
	//if starting with Logon View uncomment this section, and comment out the section below 
	
	LogonView *aLogonView = [[LogonView alloc] initWithNibName:@"LogonView" bundle:[NSBundle mainBundle]];
	[self setLogonView:aLogonView];
	[aLogonView release];
	aLogonView = nil;
	
	UIView *logonViewController = [logonView view];
	
	[window addSubview:logonViewController];
	[window makeKeyAndVisible];
}

- (void)loadMainView {
	
	MainView *aMainView = [[MainView alloc] initWithNibName:@"MainView" bundle:nil];
	aMainView.view = [aMainView.mainTabBar view];
	[self setMainView:aMainView];
	[aMainView release];
	
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:2.0];
	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
	NSArray *currentSubviews = self.window.subviews;
	UIView *viewToRemove = [currentSubviews objectAtIndex:[currentSubviews count] -1];
	[viewToRemove removeFromSuperview];
	[self.window addSubview:[mainView view]];
	[UIView commitAnimations];
}

- (void)loadUserProfileView {
	
	UserProfile *aUserProfileView = [[UserProfile alloc] initWithNibName:@"UserProfile" bundle:nil];
	[self setUserProfileView:aUserProfileView];
	[aUserProfileView release];
	
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:2.0];
	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
	[self.window addSubview: [userProfileView view]];
	[UIView commitAnimations];
	
}

- (void)loadCheckInViewWithTeams: (NSMutableArray *) teamsArg andLocations:(NSMutableArray *)nearbyLocationsArg{
	CheckInView *aCheckInView = [[CheckInView alloc] initWithTeams:teamsArg andLocations:nearbyLocationsArg];
	[self setCheckInPage:aCheckInView];
	[aCheckInView release];
	
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:2.0];
	[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:window cache:YES];
	[self.window addSubview: [checkInPage view]];
	[UIView commitAnimations];
}

- (void)dealloc {
    [logonView release];
	[mainView release];
	[userProfileView release];
	[checkInPage release];
	[JSessionCookieValue release];
    [window release];
    [super dealloc];
}



@end
